<template>
  <div>
    
    <div class="chain-link-bar-wrapper">
  		<el-breadcrumb separator-class="el-icon-arrow-right">
	  		<el-breadcrumb-item>积分管理</el-breadcrumb-item>
	  		<el-breadcrumb-item to="/commission">积分列表</el-breadcrumb-item>
	  	</el-breadcrumb>  
	  </div>

  

    <el-card class="box-card">
      <div slot="header" class="clearfix">
        <span>会员积分列表</span>
      </div>

      <div class="app-diliver-10"></div>

      <div>
        <div class="app-display-inline app-margin-h-20">
          <span class="color-black-second font-size-text">手机号：</span>
          <el-input
            placeholder="手机号"
            v-model="page.phone"
            style="width: 260px;"
            clearable
              ></el-input>
			<span class="color-black-second font-size-text">姓名：</span>
			<el-input
			placeholder="姓名"
			v-model="page.username"
			style="width: 260px;"
			clearable
			></el-input>
        </div>

        <div class="app-display-inline app-margin-h-20">
          <SubmitButton
            type="primary"
            plain
            icon="el-icon-search"
            :before-submit="()=>{this.page.pageNum = 1}"
            :post-option="{
              url: searchUrl,
              data: page,
              callback: searchCB,
            }">搜索</SubmitButton>
        </div>
      </div>



      <div class="app-diliver-15"></div>
      <div class="app-diliver-15"></div>

      
      <el-table :data="balanceList" stripe border style="width: 100%" class="nc-table-btn-ctrl">
        
        <el-table-column 
          type="index"
          :index="indexMethod">
        </el-table-column>

        <el-table-column prop="full_name" label="姓名" ></el-table-column>
        <el-table-column prop="phone" label="电话" ></el-table-column>
        <el-table-column 
          label="积分">
          <template slot-scope="scope">
            <span class="color-success text-bold">{{scope.row.money}}</span>
          </template>  
        </el-table-column>
		<el-table-column
		  label="最后获取积分">
		  <template slot-scope="scope">
		    <span class="color-success text-bold">{{scope.row.create_time}}</span>
		  </template>  
		</el-table-column>
        <el-table-column
          label="状态" >
          <template slot-scope="scope">
            <span v-if="scope.row.is_valid == 1" class="color-success text-bold">正常</span>
            <span v-if="scope.row.is_valid == 0" class="color-danger text-bold">异常</span>
          </template>  
        </el-table-column>
        <el-table-column label="操作">
          <template slot-scope="scope">
            <el-button
              size="mini"
              type="primary"
              plain
              @click="showDetailListDialogHandle(scope.row.user_id)">积分明细</el-button>
          </template>
        </el-table-column>
        

      </el-table>


      <div class="pager-bar-wrapper">
        <el-pagination
          background
          layout="prev, pager, next, total"
          :total="page.totalRow"
          :page-size="page.pageSize"
          :current-page="page.pageNum"
          @current-change="pageNumChange"
          @prev-click="pageNumChange"
          @next-click="pageNumChange"
          @size-change="pageSizeChange"
          >
        </el-pagination>
      </div>


    </el-card>
	

    
    <DetailListDialog :is-show="detailListDialogVisible" :user-info-fun="()=>{return this.userInfoForDetailList()}"></DetailListDialog>
    


  </div>
</template>


<script>
  import CommissionApi from '../../api/CommissionApi'

  import JsonKit from '../../kit/JsonKit'

  import DetailListDialog from './DetailListDialog'
  import SubmitButton from '../common/SubmitButton'
  import NcButton from '../common/NcButton'
  

  import { mapGetters } from 'vuex'

  export default {
    components: {
      SubmitButton, NcButton, DetailListDialog
    },
    data(){
      return {
        page: {
          phone: '',
		  username:'',
          pageNum: 1,
          pageSize: 10
        },

        balanceList: [],

        searchUrl: CommissionApi.URL_LIST,

        detailListDialogVisible: false,
        userIdForDetailList: 0,
      }
    },
    computed: {
      ...mapGetters(['hasPerm'])
    },
    mounted(){
       this.getPage();
    },
    created(){
      this.$root.eventHub.$on('closeDetailListDialog', this.hideDetailListDialog);
    },
    beforeDestroy: function(){
      this.$root.eventHub.$off('closeDetailListDialog', this.hideDetailListDialog);
    },
    methods: {
      searchCB(json){
        this.balanceList = json.list;
        this.setPage(json);
      },
      getPage(){
        CommissionApi.list(this.page, json=>{
          this.balanceList = json.list;
          this.setPage(json);
        });
      },
      pageNumChange(pageNum){
        this.page.pageNum = pageNum;
        this.getPage();
      },
      pageSizeChange(pageSize){
        this.page.pageSize = pageSize;
        this.getPage();
      },
      setPage(json){
        this.page.pageNum = json.pageNum;
        this.page.pageSize = json.pageSize;
        this.page.totalRow = json.totalRow;
      },
      indexMethod(index){
        return index + 1 + (this.page.pageNum - 1) * this.page.pageSize
      },
      showDetailListDialogHandle(userId){
        this.userIdForDetailList = userId;
        this.detailListDialogVisible = true;
      },
      userInfoForDetailList(){
        let userInfo = JsonKit.getOf(this.balanceList, 'user_id', this.userIdForDetailList);
        return userInfo;
      },
      hideDetailListDialog(){
        this.detailListDialogVisible = false;
      },
    }
  }
</script>
